package com.example.HelloSpace.viewmodels;


import android.util.Log;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.example.HelloSpace.models.MissionInfoModel;
import com.example.HelloSpace.repository.MissionRepository;

import java.util.List;

public class MissionListViewModel extends ViewModel {
    private final MutableLiveData<List<MissionInfoModel>> allMissions = new MutableLiveData<>();
    private final MissionRepository repository;

    public MissionListViewModel(MissionRepository repository) {
        this.repository = repository;
        loadMissionList();
    }

    public LiveData<List<MissionInfoModel>> getAllMissions() {
        return allMissions;
    }

    private void loadMissionList() {
        repository.getAllMissions().observeForever(missions -> {
            allMissions.setValue(missions);
        });
    }
    public void refreshMissions() {
        repository.refreshMissions();
    }
    public void setSelectedMission(MissionInfoModel missionInfoModel) {
        repository.setSelectedMission(missionInfoModel);
    }
    public LiveData<MissionInfoModel> getSelectedMission() {
        return repository.getSelectedMission();
    }

}